#include "imgwidget.h"
#include "threadmanager.h"
#include <QPainter>
#include <QRgb>

IMGWIDGET::IMGWIDGET(ThreadManager* m,QWidget* parent)
    :QWidget (parent),manager(m)
{
    this->setFixedSize(image_param::imageWidth,image_param::imageHeight);
}
IMGWIDGET::~IMGWIDGET() {

}
void IMGWIDGET::paintEvent(QPaintEvent*) {
#if 0
    static int cnt = -1;
    ++cnt;
#endif
    QPainter painter(this);
    QImage image(
                (uchar*)pixels,
                image_param::imageWidth,
                image_param::imageHeight,
                QImage::Format_ARGB32
                );
    for (int x = 0; x < width(); ++x) {
        for (int y = 0; y < height(); ++y) {
            int index = y*width()+x;
            pixels[index]=this->manager->processor->pixels[index];
        }
    }
    painter.drawImage(0,0,image);
#ifdef MY_DEBUG
    qDebug()<<"draw cnt:"<<cnt;
#endif
}
